﻿using System;
using System.Windows.Forms;
using DesignerHelper.Addons;
using SpreadsheetGear;

namespace WorkbookDesigner.Addons.WorkbookExplorer
{
    public partial class Outline : UserControl, IMarine<IOutline>
    {
        public Outline()
        {
            InitializeComponent();
        }

        public Outline(IOutline outline) : this()
        {
            Ol = outline;
            Init();
        }

        private IOutline Ol { get; set; }

        void IMarine<IOutline>.TriggerInit(IOutline outline)
        {
            Ol = outline;
            Init();
        }

        void IScv<IOutline>.TriggerReset()
        {
            Init();
        }

        void IScv<IOutline>.TriggerSet()
        {
            IOutline outline = Ol;
            outline.SummaryColumn = checkBoxRight.Checked ? SummaryColumn.Right : SummaryColumn.Left;
            outline.SummaryRow = checkBoxBelow.Checked ? SummaryRow.Below : SummaryRow.Above;
        }

        private void Init()
        {
            IOutline outline = Ol;
            switch (outline.SummaryColumn)
            {
                case SummaryColumn.Right:
                    checkBoxRight.Checked = true;
                    break;
                case SummaryColumn.Left:
                    checkBoxRight.Checked = false;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            switch (outline.SummaryRow)
            {
                case SummaryRow.Below:
                    checkBoxBelow.Checked = true;
                    break;
                case SummaryRow.Above:
                    checkBoxBelow.Checked = false;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        Control IScv<IOutline>.GetControl()
        {
            return this;
        }
    }
}